import scrapy
from maitian.items import MaitianItem

class MaitianSpider(scrapy.Spider):
    name = "blog"
    start_urls = ['https://blog.csdn.net/qq_38200548/article/list/2']
    def parse(self, response):
        for blog_item in response.xpath('//div[@class="article-list"]'):
            yield {
                'title': blog_item.xpath('.//h4/a/text()').extract_first().strip(),
                'summary': blog_item.xpath('.//p[@class="content"]/a/text()').extract_first(),
                'reads': blog_item.xpath('.//span[@class="num"]/text()').extract_first(),
                'date': blog_item.xpath('.//div[@class="info-box d-flex align-content-center"]//span[@class="date"]/text()').extract_first()
            }

        next_page_url = response.xpath('//div[@id="paging"]/a[@class="down_page"]/@href').extract_first()
        if next_page_url is not None:
            yield scrapy.Request(response.urljoin(next_page_url))
